package com.example.javabasic.thread.classtwo.future.demo2;

import java.util.Random;

public class ClientThread extends Thread {
    //消息队列
    private final RequestQueue queue;
    //消息内容
    private final String sendValue;
    //随机数
    private final Random random;


    public ClientThread(RequestQueue queue,String sendValue) {
        this.queue = queue;
        this.sendValue = sendValue;
        random = new Random(System.currentTimeMillis());
    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("Client-->"+sendValue);
            //写入队列
            queue.setRequest(new Request(sendValue));
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
